/*
 * Copyright (c) 2018. czmc All Rights Reserved.
 * Author: czmc
 * Email: zxc6355533@163.com
 * Encoding: UTF-8
 */

package top.stime21.myneighbours.module.edit

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import top.stime21.myneighbours.R
import top.stime21.myneighbours.data.entity.Skill

/**
 * Author: czmc  Email: @tuwan21.com
 * Version:	1.0  Date:3/6/2018
 */

class SpinnerAdapter : BaseAdapter {
    private var context: Context? = null

    constructor(context: Context) {
        this.context = context
    }

    var data: List<Skill>? = arrayListOf()
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        var tv: TextView
        var v: View
        if (convertView == null) {
            v = LayoutInflater.from(context).inflate(R.layout.item_spinner, null,false)
            tv = v.findViewById<TextView>(R.id.tv_item_name)
            v!!.tag = tv
        } else {
            v = convertView
            tv =v.tag as TextView
        }
        tv.setText(getItem(position)!!.name)
        return v!!
    }

    override fun getItem(p0: Int): Skill {
        return data!!.get(p0)
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        return data!!.size
    }

    fun setDataUpdate(data: List<Skill>?) {
        if (data != null) {
            this.data = data
            notifyDataSetChanged()
        }
    }


}